package com.spzx.common.service.feign; // 定义包路径

import feign.RequestInterceptor; // 导入Feign的RequestInterceptor接口
import feign.RequestTemplate; // 导入Feign的RequestTemplate类
import jakarta.servlet.http.HttpServletRequest; // 导入HttpServletRequest类
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; // 导入ServletRequestAttributes类

// 实现Feign的请求拦截器，用于在Feign请求中添加用户的token
public class UserTokenFeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String token = request.getHeader("token");
        requestTemplate.header("token" , token) ;
    }

}